//
//  AnswerTableViewCell.m
//  AssistantDriving
//
//  Created by dcr on 2017/1/10.
//  Copyright © 2017年 邓兆太. All rights reserved.
//

#import "AnswerTableViewCell.h"

@implementation AnswerTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    
    NSString * identifier = NSStringFromClass([AnswerTableViewCell class]);
    AnswerTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[AnswerTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat padding = kSpace;
    
    CGFloat numberImageX = padding;
    CGFloat numberImageW = 30;
    CGFloat numberImageH = numberImageW;
    CGFloat numberImageY = (self.height - numberImageH) * 0.5f;
    self.numberImage.frame = CGRectMake(numberImageX, numberImageY, numberImageW, numberImageH);
    
    CGFloat numberLabelX = padding;
    CGFloat numberLabelW = 30;
    CGFloat numberLabelH = numberLabelW;
    CGFloat numberLabelY = (self.height - numberImageH) * 0.5f;
    self.numberLabel.frame = CGRectMake(numberLabelX, numberLabelY, numberLabelW, numberLabelH);
    
    CGFloat answerLabelX = numberImageX + numberImageW + padding;
    CGFloat answerLabelY = 0;
    CGFloat answerLabelW = (self.width - answerLabelX - padding);
    CGFloat answerLabelH = self.height;
    self.answerLabel.frame = CGRectMake(answerLabelX, answerLabelY, answerLabelW, answerLabelH);
}

- (UIImageView *)numberImage {
    if (!_numberImage) {
        _numberImage = [UIImageView new];
        _numberImage.contentMode = UIViewContentModeScaleAspectFill;
        _numberImage.clipsToBounds = YES;
        _numberImage.layer.borderColor = [UIColor clearColor].CGColor;
        _numberImage.layer.borderWidth = 0.5f;
    }
    return _numberImage;
}

- (UILabel *)numberLabel {
    
    if (!_numberLabel) {
        _numberLabel = [UILabel new];
        _numberLabel.textColor = KC02_2c2c2c;
        _numberLabel.backgroundColor = [UIColor colorWithRed:1.00 green:0.66 blue:0.00 alpha:1.00];
        _numberLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _numberLabel;
}

- (UILabel *)answerLabel {
    
    if (!_answerLabel) {
        _answerLabel = [UILabel new];
        _answerLabel.textColor = KC02_2c2c2c;
        _answerLabel.numberOfLines = 0;
        _answerLabel.font = WeekFont3;
        _answerLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _answerLabel;
}

- (void)setupSubviews {
    [self.contentView addSubview:self.numberLabel];
    [self.contentView addSubview:self.numberImage];
    [self.contentView addSubview:self.answerLabel];
}

+ (CGFloat)cellHeight {
    return 44;
}

@end
